import { GCellRenderer } from "../../../../com/mui/controls/GCellRenderer";
import { BaseItem } from "../common/BaseItem";
import { ExplorerItemInfo } from "../../model/ExplorerItemInfo";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { Cache } from "../../cache/Cache";
import { EActiveType } from "../../../../Message/Public/EActiveType";
import { ItemData } from "../../resource/info/ItemData";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ResFileConst } from "../../resource/ResFileConst";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
//class TreasureShowItemRenderer
    
    export  class TreasureShowItemRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            return;
        }

        protected /* override */ configUI(): void
        {
            this._item = new BaseItem();
            this._item.setSize(60, 60);
            this._item.move(18, 18);
            this._item.isDragAble = false;
            this._item.isDropAble = false;
            addChild(this._item);
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=false;
            var loc2=null;
            super.data = arg1;
            if (!(arg1 == null) && arg1 is ExplorerItemInfo) 
            {
                if (this._bg == null) 
                {
                    this._bg = ObjCreate.createBg(15, 15, 66, 66, null, ImagesConst.PackItemBg);
                }
                addChildAt(this._bg, 0);
                if (this._lightBg == null) 
                {
                    this._lightBg = new Object /* flash.display.Bitmap */();
                    this._lightBg.y = -1;
                }
                addChildAt(this._lightBg, 0);
            }
            else 
            {
                if (this._bg && this._bg.parent) 
                {
                    removeChild(this._bg);
                }
                if (this._lightBg && this._lightBg.parent) 
                {
                    removeChild(this._lightBg);
                }
            }
            if (!(arg1 == null) && arg1 is ExplorerItemInfo) 
            {
                loc1 = Cache.instance.active.isActiveInEffect(EActiveType._EActiveTypeNewExploreItem);
                if (loc1) 
                {
                    loc2 = new ItemData(arg1.activeItem);
                }
                else 
                {
                    loc2 = new ItemData(arg1.item);
                }
                this._item.itemData = loc2;
            }
            else if (!(arg1 == null) && arg1 is Object) 
            {
                this._itemData = arg1.itemData as ItemData;
                this._item.itemData = this._itemData;
                this._item.amount = arg1.updateAmount;
            }
            else if (arg1 == null) 
            {
                this._itemData = null;
                this._item.itemData = null;
            }
            this._item.drawNow();
            LoaderHelp.addResCallBack(ResFileConst.treasure, this.onResLoaded);
            return;
        }

        /* internal  */onResLoaded(): void
        {
            this._lightBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.TreasureLight);
            return;
        }

        /* internal */ /* var */_item: BaseItem;

        /* internal */ /* var */_itemData: ItemData;

        /* internal */ /* var */_bg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_lightBg: Object /* flash.display.Bitmap */;
    }
